//
//  UIScreen.swift
//  DawnFoundation
//
//  Created by 崔成成 on 2021/8/14.
//

import UIKit

public extension UIScreen {

    static var safeAreaInsets: UIEdgeInsets {
        return UIApplication.shared._keyWindow?.safeAreaInsets ?? .zero
    }
    
    static var safeTop: CGFloat {
        return safeAreaInsets.top
    }
    
    static var safeBottom: CGFloat {
        return safeAreaInsets.bottom
    }
    
    static var navH: CGFloat {
        return 47 + safeTop
    }
    
    static var tabBarH: CGFloat {
        return 44 + safeBottom
    }
    
    static var statusBarH: CGFloat {
        return UIApplication.shared.statusBarFrame.height
    }
    
    static var width: CGFloat {
        return UIScreen.main.bounds.width
    }
    
    static var height: CGFloat {
        return UIScreen.main.bounds.height
    }
    
    static var margin: CGFloat {
        return 12.adapter
    }
    
    var launchImage: UIImage? {
        let viewSize = UIScreen.main.bounds.size
        var viewOrientation = "Landscape"
        if UIApplication.shared.statusBarOrientation == .portraitUpsideDown || UIApplication.shared.statusBarOrientation == .portrait {
            viewOrientation = "Portrait"
        }
        var launchImage:String? = nil
        if let imagesDict = Bundle.main.infoDictionary!["UILaunchImages"] as? [[String:Any]] {
            for dict in imagesDict {
                let imageSize = NSCoder.cgSize(for: dict["UILaunchImageSize"] as! String)
                if imageSize == viewSize && viewOrientation == dict["UILaunchImageOrientation"] as! String {
                    launchImage = dict["UILaunchImageName"] as? String
                }
            }
        }
        if let img = launchImage {
            return UIImage(named: img)
        }
        return nil
    }
    
    
    
}
